import { defineStore } from 'pinia'
import { UserState } from '@/stores/interface'

export const useUserStore = defineStore('user-store', {
  state: (): UserState => ({
    token: localStorage.getItem('token') ?? '',
    adminInfo: JSON.parse(localStorage.getItem('adminInfo') ?? '{}'),
    staticRouter: []
  }),
  getters: {},
  actions: {
    // Set Token
    setToken(token: string) {
      this.token = token
      localStorage.setItem('token', token)
    },
    // Set setUserInfo
    setUserInfo(adminInfo: UserState['adminInfo']) {
      this.adminInfo = adminInfo
      localStorage.setItem('user', JSON.stringify(adminInfo))
    }
  }
})
